﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Xml;
using System.Windows.Shapes;
using editor;
using xml_classes;

/// <summary>
/// Summary description for Class1
/// </summary>
public class XMLmanager
{
    public XMLmanager()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    //Call: MainCharecter = (Character)XMLmanager.Deserialize(MainCharecter.GetType(), FullPath);
    public static object Deserialize(Type typeToDeserialize, string path)
    {
        FileStream fs = new FileStream(path,
            FileMode.Open);
        XmlDictionaryReader reader =
                XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
        DataContractSerializer ser = new DataContractSerializer(typeToDeserialize);

        // Deserialize the data and read it from the instance.
        Object deserializedObject =
            ser.ReadObject(reader, true);
        reader.Close();
        fs.Close();

        return deserializedObject;
    }

    //XMLmanager.Serialize(MainCharecter, FullPath);
    public static void Serialize(Object obj, string path)
    {
        DataContractSerializer ser = new DataContractSerializer(obj.GetType());
        XmlWriter writer = XmlWriter.Create(path);
        ser.WriteObject(writer, obj);
        writer.Close();
    }

}

